﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App.Domain
{
    /// <summary>
    /// This class should be used to select entities from Database.
    /// Selected Entities Should not be used to save modification back into the Database, 
    /// they should be used only for Display/Selection Purpose.
    /// </summary>
    public class EntityRepository
    {
        private AppEntities _Context = null;
        public EntityRepository()
        {
            _Context = new AppEntities();
        }

        #region Product Selections
        /// <summary>
        /// Gets Product By ID 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Product GetProductByID(int id)
        {
            return _Context.Products
                .Include("Company")
                .Include("Category")
                .Include("ProductImages")                
                .FirstOrDefault(P => P.ID == id);
        }
        /// <summary>
        /// Gets Products by few IDS
        /// </summary>
        /// <param name="IDs"></param>
        /// <returns></returns>
        public List<Product> GetProductByID(int[] IDs)
        {
            return _Context.Products
                .Include("Company")
                .Include("Category")
                .Include("ProductImages")
                .Where(P => IDs.Contains(P.ID)).ToList();
        }

        /// <summary>
        /// Get wish list details
        /// </summary>
        /// <param name="IDs"></param>
        /// <returns></returns>
        public List<UserWishList> GetProductWishListByID(int[] IDs, int userId)
        {
            return _Context.UserWishLists
                .Include("ProductID")
                .Include("IsActive")
                .Where(P => IDs.Contains(P.ProductID)).ToList();
        }

        /// <summary>
        /// Gets Company By ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Company GetCompanyByID(int id)
        {
            return _Context.Companies
                .Include("District")
                .Include("District.Country")
                .FirstOrDefault(P => P.ID == id);
        }
        #endregion
    }    
}
